package com.adcc.pushXml.server;

import com.adcc.pushXml.core.Udp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author LHB
 * @date 2019/11/25 16:50
 */
@Service
public class SendUdp {

    private Logger log = LoggerFactory.getLogger(ExecuteParseMsg.class);
    @Value("${udp1.host}")
    private String host1;
    @Value("${udp1.port}")
    private Integer port1;
    @Value("${udp2.host}")
    private String host2;
    @Value("${udp2.port}")
    private Integer port2;

    /**
     * port 50000
     * 发送udp报文
     */
    public void sendUdp1(String msg) {
        Udp udp = new Udp(host1, port1);
        udp.init();
        try {
            udp.sendMsg(msg);
        } catch (IOException e) {
            log.error("UDP send failed [{}]", e);
        }
        udp.close();
        log.info("###############[send udp  success]###############");
    }


    /**
     * port 50001
     * 发送udp报文
     */
    public void sendUdp2(String msg)  {

        Udp udp = new Udp(host2, port2);
        udp.init();
        try {
            udp.sendMsg(msg);
        } catch (IOException e) {
            log.error("UDP send failed [{}]", e);
        }
        udp.close();
        log.info("###############[send udp  success]###############");
    }
}
